package com.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.user.dao.restaurant.RecommendRestaurants;
import com.user.dao.user.QueryPageUser;
import com.user.dao.user.UserOrderCost;
import com.user.domain.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author YU
 * @description 针对表【user】的数据库操作Mapper
 * @Date 2023-09-21 22:17:34
 * @Entity com.user.domain.User
 */
public interface UserMapper extends BaseMapper<User> {
    /**
     * 通过账号查询用户id
     *
     * @param account 账号
     * @return 用户id
     */
    @Select("select COUNT(account) from graduation.user where account = #{account}")
    int selectByAcc(String account);

    /**
     * 通过手机号查询用户id
     *
     * @param phone 手机号
     * @return 用户id
     */
    @Select("select id from graduation.user where phone = #{phone}")
    Integer selectIdByPhone(Long phone);

    /**
     * 获取用户月度消费
     *
     * @param userId 用户id
     * @return 消费信息
     */
    @Select("select order_detail,date_format(payment_time,'%Y-%m') as payment_time from `order` where user_id = #{userId} and status = 1 or status = 3")
    List<UserOrderCost> getMonthCost(Integer userId);

    /**
     * 查询用户
     *
     * @param queryPageUser 查询条件
     * @param mapPage       分页
     * @return 订单列表
     */
    IPage<User> selectUser(QueryPageUser queryPageUser, Page<User> mapPage);

    long selectUserCount(QueryPageUser queryPageUser);

    List<RecommendRestaurants> selectByOrder();

}




